<?php

namespace app\common\model;

use app\common\exception\BusinessException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

class UserVipCombo extends Base
{
    /**
     * getListByAppId
     * @param $appId
     * @return array
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getListByAppId($appId): array
    {
        $where = [
            ['app_id', '=', $appId],
            ['status', '=', 1],
        ];
        return $this->where($where)->select()->toArray();
    }

    /**
     * getInfoById
     * @param $id
     * @return array
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getInfoById($id): array
    {
        $where = [
            ['id', '=', $id],
            ['status', '=', 1],
        ];
        return $this->where($where)->find()->toArray();
    }

    /**
     * getTimeByExpireType
     * @param $expire
     * @param $expireType
     * @param $nowTime
     * @return false|int
     * @throws BusinessException
     */
    public function getTimeByExpireType($expire, $expireType, $nowTime)
    {
        switch ($expireType) {
            case 1:
                $action = '+' . $expire . ' second';
                break;
            case 2:
                $action = '+' . $expire . ' minute';
                break;
            case 3:
                $action = '+' . $expire . ' hour';
                break;
            case 4:
                $action = '+' . $expire . ' day';
                break;
            case 5:
                $action = '+' . $expire . ' month';
                break;
            case 6:
                $action = '+' . $expire . ' year';
                break;
            default:
                throw new BusinessException('不支持的有效期类型');
        }
        return strtotime($action, $nowTime);
    }
}